/*
 * @Author: szx
 * @Date: 2022-01-16 14:06:27
 * @LastEditTime: 2022-01-16 14:25:08
 * @Description: 
 * @FilePath: \leetcode\300-399\382\392.js
 */

function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}

/**
 * @param {ListNode} head
 */
var Solution = function(head) {
    this.list = [];
    while (head != null) {
        this.list.push(head.val);
        head = head.next;
    }
};

/**
 * @return {number}
 */
Solution.prototype.getRandom = function() {
    return this.list[Math.floor(Math.random() * this.list.length)];
};


/**
 * Your Solution object will be instantiated and called as such:
 * var obj = new Solution(head)
 * var param_1 = obj.getRandom()
 */